package cn.zyjblogs.nio.zerocopy;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

public class NewIOServer {
    public static void main(String[] args) {
        InetSocketAddress inetSocketAddress = new InetSocketAddress(7001);
        try (ServerSocketChannel serverSocketChannel = ServerSocketChannel.open()){
            serverSocketChannel.bind(inetSocketAddress);
            //创建buffer
            ByteBuffer byteBuffer = ByteBuffer.allocate(4096);
            while (true){
                SocketChannel socketChannel = serverSocketChannel.accept();
                int readCount = 0;
                while (-1 != readCount){
                    readCount = socketChannel.read(byteBuffer);
                }
                //倒带position 设置为 0  mark作废
                byteBuffer.rewind();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
